from django.shortcuts import render
from rest_framework import viewsets
from rest_framework import mixins
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from rest_framework import permissions
from django.utils.timezone import now
from .serializers import MovieOrdersSerializer
from drf_movie_rimi.settings import MOVIE_ORDER

# Create your views here.
"""
用户下订单 够买电影
"""


class MovieOrdersViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin,
                         mixins.DestroyModelMixin, viewsets.GenericViewSet):
    """
    用户添加一个订单
    用户删除一个订单
    用户查看自己的订单
    """

    serializer_class = MovieOrdersSerializer
    queryset = serializer_class.Meta.model.objects.all()
    authentication_classes = (JSONWebTokenAuthentication,)
    permission_classes = (permissions.IsAuthenticated,)

    def perform_create(self, serializer):
        for i in serializer.validated_data['order_seats']:
            i.lock_time = now()
            i.status = MOVIE_ORDER['order_status']['locked']
            i.save()
        serializer.save()



"""
申请支付接口,用户通过订单号去申请支付
1.座位锁定时间为 15分钟
2.必须在5分钟内去申请支付
3.必须在10分钟内去完成支付
"""


"""
支付通知接口,通知用户支付成功
"""